VERSION 5.00
Object = "{831FDD16-0C5C-11D2-A9FC-0000F8754DA1}#2.0#0"; "MSCOMCTL.OCX"
Begin VB.UserControl cListview 
   ClientHeight    =   3465
   ClientLeft      =   0
   ClientTop       =   0
   ClientWidth     =   8565
   ScaleHeight     =   3465
   ScaleWidth      =   8565
   Begin MSComctlLib.ListView ListView1 
      Height          =   3015
      Left            =   0
      TabIndex        =   0
      Top             =   0
      Width           =   6855
      _ExtentX        =   12091
      _ExtentY        =   5318
      LabelWrap       =   -1  'True
      HideSelection   =   -1  'True
      _Version        =   393217
      ForeColor       =   -2147483640
      BackColor       =   -2147483643
      BorderStyle     =   1
      Appearance      =   1
      NumItems        =   0
   End
End
Attribute VB_Name = "cListview"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = True
Option Explicit
Public Event UserOnline(ByVal Username As String, ByVal Message As String)
Public Event UserUpdate(ByVal Username As String, ByVal Message As String)
Public Event UserInformation(ByVal Username As String, ByVal Client As String, ByVal Flags As String, ByVal Ping As String, ByVal Socket As String)

Public Function AddNewColumn(Optional ColumnName As String, Optional ColumnWidth As Long)
    With ListView1
        .View = lvwReport
        .ColumnHeaders.Add(, , ColumnName, ColumnWidth).Tag = ColumnName
        .ColumnHeaders(1).Alignment = lvwColumnLeft
    End With
End Function

Public Function AddUser(Username As String, Optional Client As String, Optional Flags As String, Optional Ping As String, Optional Socket As String)
    If IsOnline(ListView1, Username) = True Then
                    Debug.Print "That Account is already in use"
                Else
                    With ListView1
                        With .ListItems
                            With .Add(, , Username) 'username
                             .ListSubItems.Add , , Client 'client
                             .ListSubItems.Add , , Flags 'flags
                             .ListSubItems.Add , , Ping 'ping
                             .ListSubItems.Add , , Socket 'socket
                             
                            End With
                        End With
                    End With
                End If
        
End Function

Public Function RemoveUser(Username As String)
    Dim i As Integer
    Dim tClient As String
    Dim tFlags As String
    Dim tPing As String
    Dim tSocket As String
     With ListView1
        For i = 1 To .ListItems.Count
 '           If .ListItems.item(i) = Username Then
 '               tClient = .ListItems.item(i).ListSubItems(1)
 '               tFlags = .ListItems.item(i).ListSubItems(2)
 '               tPing = .ListItems.item(i).ListSubItems(3)
 '               tSocket = .ListItems.item(i).ListSubItems(4)
               ' FindUser = Name & Client & flag & Ping & socket
'                RaiseEvent UserUpdate(Username, "Gone Offline")
'                RaiseEvent UserInformation(Username, tClient, tFlags, tPing, tSocket)
                
                Exit Function
            Else
             '   FindUser = "Not Found"
 '               RaiseEvent UserUpdate(Username, "was not found")
            End If
        Next i
     End With
End Function

Public Function FindUser(Username As String)
    Dim i As Integer
    Dim tClient As String
    Dim tFlags As String
    Dim tPing As String
    Dim tSocket As String
     With ListView1
        For i = 1 To .ListItems.Count
            If .ListItems.item(i) = Username Then
                tClient = .ListItems.item(i).ListSubItems(1)
                tFlags = .ListItems.item(i).ListSubItems(2)
                tPing = .ListItems.item(i).ListSubItems(3)
                tSocket = .ListItems.item(i).ListSubItems(4)
               ' FindUser = Name & Client & flag & Ping & socket
                RaiseEvent UserUpdate(Username, "Online Now")
                RaiseEvent UserInformation(Username, tClient, tFlags, tPing, tSocket)
                
                Exit Function
            Else
             '   FindUser = "Not Found"
                RaiseEvent UserUpdate(Username, "is offline")
            End If
        Next i
     End With
End Function

Public Function ModifyUser(Username As String, Optional Client As String, Optional Flags As String, Optional Ping As String)
    Dim i As Integer
        For i = 1 To ListView1.ListItems.Count
            With ListView1
            If .ListItems.item(i) = Username Then
                If Not Client = "" Then .ListItems.item(i).ListSubItems(1) = Client
                If Not Flags = "" Then .ListItems.item(i).ListSubItems(2) = Flags
                If Not Ping = "" Then .ListItems.item(i).ListSubItems(3) = Ping
                Debug.Print "User Change Successful"
                RaiseEvent UserUpdate(Username, "Change's Successful")
                Exit Function
            Else
                Debug.Print "User Not Found"
                RaiseEvent UserUpdate(Username, "Was not found!")
            End If
            End With
        Next i
        
End Function


Private Function IsOnline(List As ListView, Username As String) As Boolean
    Dim i As Integer
        For i = 1 To List.ListItems.Count
            If List.ListItems.item(i) = Username Then
                IsOnline = True
                Call FindUser(Username)
                Exit Function
            Else
                IsOnline = False
                
            End If
            
        Next i
End Function

